package com.yanxu.design01_singleton.destroy.reflection_destory.lazy;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/14-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class Test {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        LazyInstance instance = LazyInstance.getInstance();
        System.out.println("LazyInstance Instance: " + instance);

        Class<LazyInstance> lazyInstanceClass = LazyInstance.class;
        Constructor<LazyInstance> constructor = lazyInstanceClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        LazyInstance lazyInstance = constructor.newInstance();
        System.out.println("LazyInstance Instance: " + lazyInstance);

        System.out.println(instance==lazyInstance);

        /*
        * 貌似解决了单例的问题。
        * 但是其实并没有解决。因为在代码中加了 flag 这样的标记位，
        * 但是，不要忘记了反射的威力，反射可以修改 flag 的值的啊!!!!
        *
        * */
    }
}